package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Favorites;
import cn.wolfcode.trip.base.mapper.FavoritesMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IFavoritesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoritesServiceImpl implements IFavoritesService{
    @Autowired
    private FavoritesMapper favoritesMapper;

    public void insertFavorites(Favorites favorites) {
        favoritesMapper.insert(favorites);
    }

    public void deleteFavorites(Favorites favorites) {
        favoritesMapper.deleteByPrimaryKey(favorites.getUserId(),favorites.getDailyId());
    }

    public PageInfo<?> getStrategyFavoritesByUserId(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Favorites> list = favoritesMapper.getStrategyFavoritesByUserId(qo.getUserId());
        return new PageInfo(list);
    }

    public Long getStrategyFavoritesCounts(Long userId) {
        return favoritesMapper.getStrategyFavoritesCounts(userId);
    }
    public Long getTravelFavoritesCounts(Long userId) {
        return favoritesMapper.getTravelFavoritesCounts(userId);
    }


    public PageInfo<?> getTravelFavoritesByUserId(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Favorites> list = favoritesMapper.getTravelFavoritesByUserId(qo.getUserId());
        return new PageInfo(list);
    }


    public PageInfo<?> getDailyFavoritesByUserId(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Favorites> list = favoritesMapper.getDailyFavoritesByUserId(qo.getUserId());
        return new PageInfo(list);
    }

    public Long getDailyFavoritesCounts(Long userId) {
        return favoritesMapper.getDailyFavoritesCounts(userId);
    }
}